<template>
	<div class="padding-across-10" v-loading="loading" element-loading-text="拼命加载中">
		<headerOpreate style="padding-bottom: 3px" :opreate-datas="opreateDatas" v-on:executeAction="executeAction"></headerOpreate>
		<div class="edit-mission">
			<div class="clearfloat">
				<div class="tree_list">
					<p class="panel_title">{{$t('message.deviceList')}}</p>
					<el-tree :show-overflow-tooltip="true" :data="datas" ref="tree" :highlight-current="true" show-checkbox :props="props" :default-expand-all="true" node-key="sn"></el-tree>
				</div>
				<div class="container">
					<p class="panel_title">标定文件列表</p>
					<section class="container-section">
						<div style="width: 100%;">
							<el-button style="margin: 5px 0" size="small" type="primary" @click="push"><i class="el-icon-circle-check el-icon--left"></i>确认推送</el-button>
							<el-table border style="width: 100%;" :data="tableData">
								<el-table-column :show-overflow-tooltip="true" label="" width="50">
									<template slot-scope="scope">
										<el-radio :label="scope.row" v-model="fileForm" @change.native="getCurrentRow(scope.row)">&nbsp;</el-radio>
									</template>
								</el-table-column>
								<el-table-column :show-overflow-tooltip="true" label="名称" align="center" prop="name">
								</el-table-column>
								<el-table-column :show-overflow-tooltip="true" label="文件类型" align="center">
									<template slot-scope="scope">
										<span v-if="scope.row.type == 8">幕布自检标定文件</span>
										<span v-if="scope.row.type == 9">投影机调度标定文件</span>
									</template>
								</el-table-column>
								<el-table-column :show-overflow-tooltip="true" label="适配设备" align="center">
									<template slot-scope="scope">
										<span>多媒体智能终端</span>
									</template>
								</el-table-column>
								<el-table-column :show-overflow-tooltip="true" label="创建者" align="center" prop="uid"></el-table-column>
								<el-table-column :show-overflow-tooltip="true" label="上传时间" align="center" prop="time" width="200"></el-table-column>
								<el-table-column :show-overflow-tooltip="true" label="描述" align="center" prop="desc"></el-table-column>
							</el-table>
							<div class="block" style="text-align:right;margin-bottom:60px">
								<el-pagination @current-change="handleCurrentChange" @size-change="handleSizeChange" :current-page="currentPage" :page-size="pageSize" :page-sizes="[10,20,30,40,50]" layout="total,sizes, prev, pager, next, jumper" :total="totalSize">
								</el-pagination>
							</div>
						</div>
					</section>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
	import $ from 'jquery'
	import headerNave from '../../../../components/headerNave'
	import { GloabFun, HttpServer } from '../../../../assets/js/common.js'
	import headerOpreate from '../../../../components/headerOpreate'
	export default {
		components: {
			headerNave,
			headerOpreate
		},
		data() {
			return {
				loading: false,
				datas: [],
				props: {
					label: 'name',
					id: 'sn'
				},
				tableData: [],
				currentPage: 1,
				pageSize: 10,
				totalSize: 0,
				fileForm: {}
			}
		},
		props: {
			subArgs: {
				type: Object,
				default: function() {
					return {};
				}
			}
		},
		methods: {
			executeAction(action) {
				if(action) {
					this[action]();
				}
			},
			//单选
			getCurrentRow(row) {

			},
			//获取所有中控设备
			getAllDeviceInfo() {
				HttpServer.httpPost.call(this, '/Api/Device/Info', {category: ['MultimediaIT']}, function(response) {}, function(response) {
					if(response.data.code === 0) {
						this.datas = response.data.deviceinfo;
					}
				});
			},
			//去掉时间中的T
			formateData(array) {
				for(var i = 0; i < array.length; i++) {
					var index1 = array[i].time.indexOf("T");
					array[i].time = array[i].time.substring(0, index1) + " " + array[i].time.substring(index1 + 1, index1 + 9);
				}
			},
			handleCurrentChange(val) {
				this.currentPage = val;
				this.getDatas();
			},
			handleSizeChange(val) {
				this.pageSize = val;
				this.getDatas();
			},
			push() {
				if(this.$refs.tree.getCheckedKeys().length === 0){
					this.$notify.warning({
						title: '提示',
						message: '请选择推送设备',
						duration: 2500
					});
				}else{
					this.loading = true;
					var param = {
						sns: this.$refs.tree.getCheckedKeys(),
						filename: this.fileForm.name,
						path: this.fileForm.url,
						md5: "",
						UserId: parseInt(GloabFun.getKeyId())
					}
					HttpServer.httpPost.call(this,'/Api/Peripheral/PushCalibrationFile',param,function(response) {}, function(response){
						this.loading = false;
						if(response.data.code === 0){
							if(response.data.response.length === 0){
								this.$notify.error({
									title: '错误',
									message: '操作无响应',
									duration: 2500
								});
							}else{
								var failSns = [];
								response.data.response.forEach(function(item){
									if(item.code != 0){
										failSns.push(item.sn)
									}
								})
								if(failSns.length > 0){
									const h = this.$createElement;
									this.$msgbox({
										title: '以下设备推送失败！',
										message: h('p', { style: 'word-wrap:break-word' }, failSns.join()),
										confirmButtonText: '确定'
									})
								}else {
									this.$notify({
										title: '成功',
										message: '操作成功',
										type: 'success',
										duration: 2500
									});
								}
							}
						}else{
							this.$notify.error({
								title: '错误',
								message: response.data.msg,
								duration: 2500
							});
						}
					})
				}
			},
			//获取所有文件
			getDatas() {
				this.tableData = [];
				var param = {
					types: [8,9],
					index: this.currentPage,
					pagesize: this.pageSize,
					createdby: this.value === 1 ? this.searchModel : '',
					name: this.value === 0 ? this.searchModel : '',
					devicetype: this.deviceCategory
				}
				HttpServer.httpPost.call(this, '/Api/User/File/CommonFileInfo', param, function(response) {}, function(response) {
					if(response.data.code === 0) {
						if(response.data.Info_.length > 0) {
							this.formateData(response.data.Info_);
							this.tableData = response.data.Info_;
							this.totalSize = response.data.totalcount;
							this.fileForm = this.tableData[0];
						}
						this.getAllDeviceInfo();
					} else {
						this.$notify.error({
							title: '错误',
							message: response.data.msg,
							duration: 2500
						});
					}
				});
			},
		},
		created() {
			this.getDatas();
		}
	}
</script>
<style lang="less">
	.schedule-task {
		.tree_list {
			.el-tree {
				overflow: auto;
			}
			.el-tree-node__expand-icon {
				display: none;
			}
			.el-checkbox {
				margin-left: 10px;
			}
		}
	}
	
	.edit-mission {
		.el-dialog__body {
			position: relative;
		}
		.clearfloat {
			height: 530px;
			max-height: 600px;
		}
	}
</style>
<style scoped lang="less">
	.tree_list {
		width: 220px;
		float: left;
		height: 100%;
		.panel_title {
			border-radius: 3px;
			background-color: #000;
			color: white;
		}
		>div {
			width: 100%;
			height: e("calc(100% - 20px)");
		}
	}
	
	.container {
		width: e("calc(100% - 220px)");
		float: left;
		height: 100%;
		.panel_title {
			border-radius: 3px;
			background-color: #000;
			color: white;
		}
		.container-section {
			border: 1px solid #d3dce6;
			height: e("calc(100% - 20px)");
			margin-left: 10px;
			overflow-y: auto;
		}
	}
	
	.el-tree-node__expand-icon.is-leaf {
		width: 10px;
		margin: 0;
	}
</style>